class AdGroup < ApplicationRecord

  #before_save { self.email = email.downcase }
  validates :title, presence: true, uniqueness: true, length:{minimum: 2, maximum: 10 }
  validates :ad_offer, presence: true, uniqueness: true
  validates :campaign_type, presence: true
  validates :campaign_id, presence:true
  belongs_to :user
  belongs_to :campaign
  has_many :ad_group_creative_rels, dependent: :destroy
  has_many :ad_group_rpts, dependent: :destroy

  def ad_group_creative(creative_ids,ad_group_id)
    ids = []
    if creative_ids.include?","
     ids = creative_ids.split(",")
    else
      ids.push(creative_ids)
    end
ids&.each do |id|
     @ad_group_creative_rels = ad_group_creative_rels.create(ad_group_creative_id: id)
end
  end
end
